package com.cx.mall.user.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cx.mall.user.entity.UserInfo;
import com.cx.mall.user.mapper.IUserInfoMapper;
import com.cx.mall.user.service.IUserInfoService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserInfoServiceImpl extends ServiceImpl<IUserInfoMapper, UserInfo> implements IUserInfoService {

    @Override
    public UserInfo queryByUsername(String username) {
        LambdaQueryChainWrapper<UserInfo> query = new LambdaQueryChainWrapper<>(this.getBaseMapper());
        UserInfo userInfo = query.eq(UserInfo::getUsername, username).
                eq(UserInfo::getStatus, 0).
                select(UserInfo::getId, UserInfo::getUsername,
                        UserInfo::getPassword, UserInfo::getEmail,
                        UserInfo::getNickName).one();
        return userInfo;
    }

    @Override
    public List<UserInfo> queryByCreateTimeAndStatus(LocalDateTime start, LocalDateTime end, Integer status) {
        LambdaQueryChainWrapper<UserInfo> query = new LambdaQueryChainWrapper<>(this.getBaseMapper());
        List<UserInfo> list = query.between(UserInfo::getCreateTime, start, end).
                eq(UserInfo::getStatus, status).list();
        return list;
    }

}
